package src.jeu;

import java.util.Stack;

public class Tower {

	private Stack disks;
	private int capacity;
	
	Tower(int capacity){
		this.disks = new Stack();
		this.capacity = capacity;
	}
	
	public int getCapacity(){
		return this.capacity;
	}
	
	public int getDiskNB(){
		return this.disks.size();
	}
	
	public Disk getDisk(int index){
		if (index >=0 && index<getDiskNB())
		return (Disk) disks.get(index);
		else return null;
	}
	
	public Disk getTopDisk(){
		if (!isEmpty())
			return (Disk)this.disks.lastElement();//return (Disk)disks.peek();
		else
			return null;
	}
	
	public boolean isEmpty(){
		return this.disks.isEmpty();
	}
	
	public boolean isFull(){
		return this.capacity==getDiskNB();
	}
	
	public boolean isStackable(Disk disk){
		if (disk.getSize()<getTopDisk().getSize())
			return true;
		else return false;
	}
	
	public Disk pop(){
		return (Disk) disks.pop();
	}
	
	public void push(Disk disk){
		if (isFull()) System.out.println("Aie!!");
		else disks.push(disk);
	}
	
	public String toString(){
		String result = "Tower["+getDiskNB()+"/"+getCapacity()+"]";
		for (int i=getDiskNB()-1; i>=0; i--){
			result += "\n  O "+getDisk(i).toString();
		}
		return result;
	}
}
